#include "include.h"
#include "func.h"
#include "func_idle.h"

#if FUNC_IDLE_EN
extern u8 long_wakeup;
u8 spec_func_mode=0;
u8 key_timeout=0;
u8 long_hold_cnt=0;
extern void test_color(void);
extern void func_ilde_timeout(void);
extern void func_ilde_lower_power_check(void);
extern void func_reset_timeout(void);
extern void func_QRcode_disable(void);

AT(.text.func.idle.msg)
void func_idle_message(u16 msg)
{
	if(msg!=0&&msg!=0x7ff&&(msg&0x800))
	{
		printf("msg:0x%x\n",msg);
	}
    switch (msg) {

		case KU_BT:
			//func_reset_timeout();
			//test_color();
			//break;
			func_cb.sta =FUNC_BT;
			long_hold_cnt=0;
			//bsp_set_light_mode(LIGHT_SEQUENCE_12);
			break;
		case KL_BT:
			sys_cb.bt_mode=1;
			func_cb.sta =FUNC_BT;
			long_hold_cnt=0;
			break;
		case KH_SONG1:
			func_reset_timeout();
			long_hold_cnt++;
			printf("hold cnt:%d\n",long_hold_cnt);
			if(long_hold_cnt>=30)
			{
				func_cb.sta =FUNC_EXSPIFLASH_WRITE;
			}
			break;
		//case KH_HSF:
		//	func_cb.sta =FUNC_SPEAKER;

		//	break;
		case KU_EQ:
		case KLU_EQ:
			long_hold_cnt=0;
			break;
		case KH_EQ:
			long_hold_cnt++;
			printf("hold cnt:%d\n",long_hold_cnt);
			if(long_hold_cnt==10)
			{
				func_QRcode_disable();
			}		
			break;
		case KU_POWER:
			if(long_wakeup)
			{
				long_wakeup=0;
				break;
			}
			music_control(MUSIC_MSG_STOP);
			func_cb.sta = FUNC_PWROFF;
			break;
		case KL_POWER:
		case KH_POWER:
			if(long_wakeup)
			{
				break;
			}
			else
			{
				music_control(MUSIC_MSG_STOP);
				func_cb.sta = FUNC_PWROFF;
			}
			break;
		case KLU_POWER:
			long_wakeup=0;
			spec_func_mode=0;
			break;

		case KU_SONG1:
			sys_cb.song_mode=0;
			func_cb.sta =FUNC_EXSPIFLASH_MUSIC;
			break;
		case KU_SONG2:
			sys_cb.song_mode=1;
			func_cb.sta =FUNC_EXSPIFLASH_MUSIC;
			break;
		case MSG_SYS_1S:
			func_ilde_lower_power_check();
			func_ilde_timeout();

			break;
		case EVT_MIC_INSERT:
		func_idle_mic_onoff(1);
		break;
		case EVT_MIC_REMOVE:
		func_idle_mic_onoff(0);
		break;
		case EVT_MODE_3P_TO_DEMO:
		case EVT_MODE_3P_TO_HOME:
			printf("3p switch!!\n");
			music_control(MUSIC_MSG_STOP);
			sys_cb.pwrdwn_tone_en = 0;
			func_cb.sta =FUNC_PWROFF;
			break;
        default:
            func_message(msg);
            break;
    }
}
#endif // FUNC_IDLE_EN
